import { defHttp } from '@/utils/http';
import { root, sys } from '@/api/apiRoot';
import type { QuotaData, GetMarketList, ResourcesList, PliceConfirm, AddApplyData, PliceSet, DetailsInfo,ISaasIntentionApply } from './types'
import type { IResData, IQuery } from '../indexTypes';
import type { ConfirmCooperation } from '@/router/types/modules/cooperation';
import type { AuditStatusEnum, CooperationTypeEnum } from '@/enums/cooperationEnum';

const Api = {
  cooperationQuota: `${root}sys/cooperationAp/quota`,
  apList: `${root}sys/cooperationAp/list`,
  cooperatedList: `${root}sys/cooperationAp/cooperatedList`,
  marketList: `${root}sys/cooperationAp/marketList`,

  apInfoList: `${root}sys/cooperationAp/info`,
  resourcesList: `${root}sys/cooperationAp/proType`,
  selectCooperation: `${root}sys/cooperationAp/select`,

  loadPliceSet: `${root}sys/cooperationAp/loadPrice`,
  editPliceLoad: `${root}sys/cooperationAp/query`,

  addCooperation: `${root}sys/cooperationAp/add`,
  getCooperationDetails: `${root}sys/cooperationAp/get`,
  cancelCooperation: `${root}sys/cooperationAp/cancel`,
  apCooperation: `${root}sys/cooperationAp/ap`,

  isSetPlay: `${root}sys/cooperationAp/check`,

  cooperationInvitationList: sys + 'cooperationInvitation/page',
  qrcodeInstitutionInfoApi: sys + 'cooperationInvitation/getOrgQrCode',
  addCooperationInvitation: sys + 'cooperationInvitation/addInvitation',
  cooperationInvitationDetail: sys + 'cooperationInvitation/getById',
  cooperationInvitationAudit: sys + 'cooperationInvitation/audit',
  noCooperationPage: sys + 'cooperationInvitation/cooperationPage',

  saasIntentionApply:`${root}saas-intention-apply/add`,
};


/**
 * @description 获取本协会合作权益数量等信息
 * @date 16/02/2023
 * @export
 */
export function cooperationQuota(): Promise<QuotaData> {
  return defHttp.get({
    url: Api.cooperationQuota,
  });
}

/**
 * @description 获取合作申请记录
 * @date 25/02/2023
 * @export
 */
export function getApList(data: IQuery & { isCreate: CooperationTypeEnum }): Promise<IResData> {
  return defHttp.get({
    url: Api.apList,
    data
  });
}

/**
 * @description 获取合作单位列表
 * @date 25/02/2023
 * @export
 */
export function getCooperatedList(data: IQuery): Promise<IResData> {
  return defHttp.get({
    url: Api.cooperatedList,
    data
  });
}

/**
 * @description 获取合作资源列表
 * @date 25/02/2023
 * @export
 */
export function getMarketList(data: GetMarketList): Promise<IResData> {
  return defHttp.get({
    url: Api.marketList,
    data
  });
}

/**
 * @description 机构合作详情-接入,推送列表
 * @date 25/02/2023
 * @export
 */
export function getApInfoList(tenantId: number): Promise<any> {
  return defHttp.get({
    url: Api.apInfoList + `?tenantId=${tenantId}`
  });
}

/**
 * @description 资源列表
 * @date 25/02/2023
 * @export
 */
export function getResourcesList(data: any): Promise<ResourcesList[]> {
  return defHttp.get({
    url: Api.resourcesList,
    data
  });
}

/**
 * @description 选择资源-添加
 * @date 25/02/2023
 * @export
 */
export function selectCooperation(data: ConfirmCooperation): Promise<PliceConfirm[]> {
  return defHttp.post({
    url: Api.selectCooperation,
    data
  });
}

/**
 * @description 价格及分润设置-初次获取
 * @date 27/02/2023
 * @export
 */
export function loadPliceSet(data: any): Promise<PliceSet> {
  return defHttp.post({
    url: Api.loadPliceSet,
    data
  });
}

/**
 * @description 价格及分润设置-修改后计算
 * @date 27/02/2023
 * @export
 */
export function editPliceLoad(data: any): Promise<PliceSet> {
  return defHttp.post({
    url: Api.editPliceLoad,
    data
  });
}

/**
 * @description 确定发送申请
 * @date 27/02/2023
 * @export
 */
export function addCooperation(data: AddApplyData[]): Promise<any> {
  return defHttp.post({
    url: Api.addCooperation,
    data
  });
}

/**
 * @description 获取合作详情
 * @date 27/02/2023
 * @export
 */
export function getCooperationDetails(id: number): Promise<DetailsInfo> {
  return defHttp.get({
    url: Api.getCooperationDetails + `?id=${id}`
  });
}

/**
 * @description 取消合作
 * @date 28/02/2023
 * @export
 */
export function cancelCooperation(id: number): Promise<any> {
  return defHttp.get({
    url: Api.cancelCooperation + `?id=${id}`
  });
}

/**
 * @description 合作申请审核
 * @date 27/02/2023
 * @export
 */
export function apCooperation(data: any): Promise<any> {
  return defHttp.post({
    url: Api.apCooperation,
    data
  });
}

/**
 * @description 判断是否开通支付
 * @date 10/03/2023
 * @export
 */
export function isSetPlay(tenantId: number): Promise<any> {
  return defHttp.get({
    url: Api.isSetPlay + `?tenantId=${tenantId}`
  });
}


/**
 * @description 获取合作邀请记录
 * @description isCreate 0
 * @date 22/11/2023
 * @export
 * @param {(IQuery & { isCreate: 0 | 1 })} data
 */
export function getCooperationInvitationList(data: IQuery & { isCreate: 1 | 2 }) {
  return defHttp.get({
    url: Api.cooperationInvitationList,
    data
  });
}

/**
 * @description 根据合作码获取机构信息
 * @date 22/11/2023
 * @export
 * @param {string} uuid
 */
export function getQrcodeInstitutionInfo(uuid: string) {
  return defHttp.get({
    url: Api.qrcodeInstitutionInfoApi + `/${uuid}`
  });
}

/**
 * @description 合作管理添加邀请记录
 * @date 22/11/2023
 * @export
 * @param {number} toTenantId 对方租户ID
 */
export function addCooperationInvitation(toTenantId: number) {
  return defHttp.post({
    url: Api.addCooperationInvitation,
    data: {
      toTenantId
    }
  });
}

/**
 * @description 获取邀请记录详情
 * @date 22/11/2023
 * @export
 * @param {number} id
 */
export function getCooperationInvitationDetail(id: number) {
  return defHttp.get<DetailsInfo>({
    url: Api.cooperationInvitationDetail + `/${id}`
  });
}

/**
 * @description 合作邀约审核
 * @date 22/11/2023
 * @export
 * @param {{ id: number, apStatus: AuditStatusEnum, apText: string }} data
 */
export function cooperationInvitationAudit(data: { id: number, apStatus: AuditStatusEnum, apText: string }) {
  return defHttp.post({
    url: Api.cooperationInvitationAudit,
    data
  });
}

/**
 * @description 获取暂无合作的机构列表
 * @date 22/11/2023
 * @export
 * @param {IQuery} data
 */
export function getNoCooperationPage(data: IQuery) {
  return defHttp.get({
    url: Api.noCooperationPage,
    data
  });
}

/**
 * 意向合作申请
 * @param data 
 * @returns 
 */
export function saasIntentionApply(data: ISaasIntentionApply) {
  return defHttp.post({
    url: Api.saasIntentionApply,
    data
  });
}